<!DOCTYPE html>
<html>

	<head>
		<title>岗位管理</title>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>

	<body class="easyui-layout">
		<div data-options="region:'west',split: true" style="width:20%">
			<%include("/deptStation/deptStationTree.html"){}%>
	    </div>
	    <div data-options="region:'center',border: false">
	    	<div style="padding: 5px;">
				<ul id="stationRigthTree" class="ztree"></ul>
			</div>
	    </div>
	<script type="text/javascript">
	
	//初始化岗位权限树状图
	function initStationRightTree(treeNode){
		firstAsyncSuccessFlag = 0;
		var curStationIds = "${curStationIds! }";
		var ck = true;
		if(treeNode.id == curStationIds){
			ck = false;
		}
		var stationRigthTreeSetting = {
				async : {
					enable : true,
					url : '${cxt!}/departmentStation/rightTreeData',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					otherParam : {
						"stationIds" : treeNode.id
					},
					type : "post"
				},
				view : {
					expandSpeed : "",
					selectedMulti : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				check : {
					enable : ck,
					chkStyle : "checkbox",
					chkboxType : {
						"Y" : "ps",
						"N" : "ps"
					}
				},
				callback : {
					beforeCheck : rightBeforeCheck,
					onAsyncSuccess : rightTreeOnAsyncSuccess
				}
			};
		$.fn.zTree.init($("#stationRigthTree"), stationRigthTreeSetting);
	}
	
	
	//rightTree加载完成后默认展开第一级
	var firstAsyncSuccessFlag = 0;
	function rightTreeOnAsyncSuccess(event, treeId, msg) {
		if (firstAsyncSuccessFlag == 0) {
			try {
				var rightTree = $.fn.zTree.getZTreeObj("stationRigthTree");
				//调用默认展开第一个结点  
				var nodes = rightTree.getNodes();
				rightTree.expandNode(nodes[0], true);

				var childNodes = rightTree.transformToArray(nodes[0]);
				rightTree.expandNode(childNodes[1], true);
				firstAsyncSuccessFlag = 1;
			} catch (err) {

			}

		}
	}
	
	function rightBeforeCheck(treeId, treeNode) {
		var lTree = $.fn.zTree.getZTreeObj("deptStationTree");
		var curStationNode = lTree.getSelectedNodes()[0];
		var url = '';
		var msg = '';
		if (treeNode.checked == false) {
			url = "departmentStation/addStationRight";
			msg = "添加成功！";
		} else if (treeNode.checked == true) {
			url = "departmentStation/delStationRight";
			msg = "删除成功！";
		}
		$.post(url, {
			"ids" : treeNode.id,
			"stationIds" : curStationNode.id
		}, function(result) {
			if (result.code == '200') {
				$.slideMsg(msg, parent.$);
			}else if(result.code == '300'){
				var parentNode = treeNode.getParentNode();
				var rightTree = $.fn.zTree.getZTreeObj("stationRigthTree");
				rightTree.reAsyncChildNodes(parentNode, "refresh");
				parent.$.messager.alert('错误', result.msg, 'error');
				return false;
			}
		}, "json");
	}
	</script>
	</body>
</html>